#!/usr/bin/env bash
# set -x
set -euo pipefail

cd $(dirname ${BASH_SOURCE[0]})
SHELL_FOLDER=$(pwd)
DEPLOY_ROOT=$(cd ../ && pwd)
source $DEPLOY_ROOT/init/base.sh

ARCH=$(uname -m)
NOTICE "CPU Archicture: $ARCH"
if [ $ARCH == "x86_64" ]; then
  jq_pkg=jq-linux-amd64
elif [ $ARCH == "aarch64" ]; then
  jq_pkg=jq-linux-arm64
else
    ERROR "Unsupported arch $ARCH"
    exit 1
fi

if [ ! -f ~/.local/bin/jq ]; then
  mkdir -p ~/.local/bin
  mkdir -pv $DEPLOY_ROOT/packages
  cd $DEPLOY_ROOT/packages
  rm -f $jq_pkg && wget $DOWNLOAD_URL/$jq_pkg --no-check-certificate
  cp -f $jq_pkg ~/.local/bin/jq
  chmod +x ~/.local/bin/jq
fi